package net;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class ParaWriter implements Runnable
{
    ObjectOutputStream out;
    Queues<msg> SendQueue;
    
    public ParaWriter(ObjectOutputStream out, Queues<msg> sq) {
        this.out = null;
        SendQueue = sq;
    }
    @Override
    public void run() {
    	//while(true)
    	{
    		
    		try{
	    		if(SendQueue.isEmpty())
	    		{
	    			Thread.sleep(200);
	    		//	continue;
	    		}
	    		msg m = (msg) SendQueue.dequeue();
	    		
	    	//	if(m.getType() == MSGType.CLIENT_UI_CLOSE)
	    		//	break; //Close write thread
	    		System.out.println("chay luong write");
                out.writeObject(m);
                
                out.flush();
                out.reset();
            }catch(Exception e){System.err.println("Writing errors");}
    	}
    }
}